using Medical.Domain.BasicManagement;
using Medical.ErrorCode;
using Medical.Interstructrue.Base;

namespace Medical.Api.Write.Service.BasicManagement
{
    /// <summary>
    /// 基础管理服务实现类
    /// 负责处理货架管理等基础数据操作
    /// </summary>
    public class BasicManagementService : IBasicManagementService
    {
        // 货架仓储接口
        private readonly IBaseRepository<Shelves> _shelfRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="shelfRepository">货架仓储接口</param>
        public BasicManagementService(IBaseRepository<Shelves> shelfRepository)
        {
            _shelfRepository = shelfRepository;
        }

        /// <summary>
        /// 添加货架
        /// </summary>
        /// <param name="shelfs">货架实体</param>
        /// <returns>操作结果</returns>
        public ApiResult<int> ShelfCreate(Shelves shelfs)
        {
            try
            {
                // 1. 调用仓储层创建货架
                var result = _shelfRepository.Create(shelfs);

                // 2. 返回成功结果
                return new ApiResult<int>
                {
                    Code = ApiEnums.Success,
                    Data = result,
                    Msg = "货架信息添加成功"
                };
            }
            catch (Exception ex)
            {
                // 3. 异常处理
                return new ApiResult<int>
                {
                    Code = ApiEnums.Success,
                    Msg = "货架信息添加失败，原因:" + ex.Message
                };
            }
        }
    }
}
